﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using Gendarme;
using Commander.Core;
using Commander.Core.AI;

namespace Commander.Prototype {
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window {
		string[] args = new string[3];
		public MainWindow() {
			InitializeComponent();
			args[0] = "--set";
			args[1] = "smells";
		}

		private void selectAssembly_Click(object sender, RoutedEventArgs e) {
			OpenFileDialog diag = new OpenFileDialog();
			diag.Multiselect = false;
			diag.ShowDialog();

			this.assemblyPath.Text = diag.FileName;

		}

		private void run_Click(object sender, RoutedEventArgs e) {
			if (string.IsNullOrEmpty(this.assemblyPath.Text)) {
				MessageBox.Show("Please select an assembly/exe");
			}
			else {
				args[2] = this.assemblyPath.Text;
			//	var runner = new ConsoleRunner();

				var defects = ConsoleRunner.CommanderExec(args);// new GendarmeRunnery(this.assemblyPath.Text).Execute();
				numberOfDefects.Content = defects.Count.ToString();
				defectLister.ProcessDefects(defects);
        Encoding enc = new Encoding(defects);
				enc.FilePath = @"C:\Users\boguste\Documents\sekele\sergcommander\trunk\Commander\Commander.Test\SubtleDuplication.txt";
        var best = CommanderGA.Launch(0.1, 0.9, 10, defects, 1.0, enc.FilePath);
       // enc.EvaluateFitness();
        MessageBox.Show(best.ToString());
			}
		}
	}
}
